//
//  RNOLLoginViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/26.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLLoginViewController.h"
#import "RNOLQuickLoginView.h"
#import "RNOLRegisterViewController.h"
#import "RNOLLoginViewModel.h"

@interface RNOLLoginViewController ()

@property (nonatomic,strong) RNOLLoginViewModel *viewModel;

@end

@implementation RNOLLoginViewController

- (RNOLLoginViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel = [[RNOLLoginViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
}

- (void)setup{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -kTopBarViewHeight, KWIDTH , KHIGHT+kTopBarViewHeight)];
    [self.view addSubview: scrollView];

    RNOLQuickLoginView *loginView = [RNOLQuickLoginView FromXIB];
    loginView.frame = CGRectMake(0, 0, KWIDTH , kLoginPageHeight);
    [scrollView addSubview: loginView];
    scrollView.contentSize = CGSizeMake(KWIDTH, CGRectGetMaxY(loginView.frame)+50);
    
    [loginView setLoginActionBlock:^{
        
    }];
    
    [loginView setSkipRegisterBlock:^{
        [self.view endEditing:YES];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self pushPageWithClass:[RNOLRegisterViewController class]];
        });
    }];
    
    RAC(self.viewModel,phoneNumber) = loginView.phoneTextField.rac_textSignal;
    RAC(self.viewModel,password) = loginView.passwordTextField.rac_textSignal;
    RAC(loginView.loginButton,enabled) = self.viewModel.enableLoginSignal;

}

@end
